module mpi_utils
    use, intrinsic :: iso_c_binding
    use mpi
    implicit none
contains
    subroutine fortran_allreduce(sendbuf, recvbuf, count, f_comm) &
        bind(c, name="fortran_allreduce_")
        real(c_double), intent(in)  :: sendbuf(*)
        real(c_double), intent(out) :: recvbuf(*)
        integer(c_int), intent(in)  :: count
        integer(c_int), intent(in)  :: f_comm  ! MPI_Fint

        integer :: ierr, comm

        comm = f_comm

        call mpi_allreduce(sendbuf, recvbuf, count, &
                         MPI_DOUBLE_PRECISION, MPI_SUM, comm, ierr)
    end subroutine
end module